#include "interact.h"

bool interact::gameActions(Perso* link)
{

    SDL_Event event;
    while (SDL_PollEvent(&event))
    {
        // check for events
        switch (event.type)
        {
            // exit if the window is closed
            case SDL_QUIT:
                return true;
                break;

            // check for keypresses
            case SDL_KEYDOWN:
            {
                    //arrow pressed
                    if (event.key.keysym.sym == SDLK_RIGHT)
                        link->move(true, "right");
                    else if (event.key.keysym.sym == SDLK_LEFT)
                        link->move(true, "left");
                    else if (event.key.keysym.sym == SDLK_UP)
                        link->move(true, "up");
                    else if (event.key.keysym.sym == SDLK_DOWN)
                        link->move(true, "down");

                    // exit if ESCAPE is pressed
                    else if (event.key.keysym.sym == SDLK_ESCAPE)
                        return true;
                    break;
            }
            case SDL_KEYUP:
            {
                //arrow released
                if (event.key.keysym.sym == SDLK_RIGHT)
                        link->move(false, "right");
                    else if (event.key.keysym.sym == SDLK_LEFT)
                        link->move(false, "left");
                    else if (event.key.keysym.sym == SDLK_UP)
                        link->move(false, "up");
                    else if (event.key.keysym.sym == SDLK_DOWN)
                        link->move(false, "down");
                    break;
            }
        } // end main switch
    } // end of events processing
}
